#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countDaysTogether(string arriveAlice, string leaveAlice, string arriveBob, string leaveBob) {
        string leftMax;
        string rightMin;
        int MonthDay[] = { 0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };


        int AliceMon = (arriveAlice[0] - 48) * 10 + (arriveAlice[1] - 48);
        int BobMon = (arriveBob[0] - 48) * 10 + (arriveBob[1] - 48);
        if (AliceMon == BobMon)
        {
            int AlDay = (arriveAlice[3] - 48) * 10 + (arriveAlice[4] - 48);
            int BobDay = (arriveBob[3] - 48) * 10 + (arriveBob[4] - 48);
            leftMax = (AlDay > BobDay) ? arriveAlice : arriveBob;
        }
        else
        {
            leftMax = (AliceMon > BobMon) ? arriveAlice : arriveBob;
        }

        AliceMon = (leaveAlice[0] - 48) * 10 + (leaveAlice[1] - 48);
        BobMon = (leaveBob[0] - 48) * 10 + (leaveBob[1] - 48);
        if (AliceMon == BobMon)
        {
            int AlDay = (leaveAlice[3] - 48) * 10 + (leaveAlice[4] - 48);
            int BobDay = (leaveBob[3] - 48) * 10 + (leaveBob[4] - 48);
            rightMin = (AlDay < BobDay) ? leaveAlice : leaveBob;
        }
        else
        {
            rightMin = (AliceMon < BobMon) ? leaveAlice : leaveBob;
        }

        int SumDay = 0;

        int startMon = (leftMax[0] - 48) * 10 + (leftMax[1] - 48);
        int endMon = (rightMin[0] - 48) * 10 + (rightMin[1] - 48);

        for (int i = startMon + 1; i < endMon; ++i)
        {
            SumDay += MonthDay[i];
            cout << i << endl;
        }

        if (startMon == endMon)
        {
            SumDay += ((rightMin[3] - 48) * 10 + (rightMin[4] - 48)) - ((leftMax[3] - 48) * 10 + (leftMax[4] - 48)) + 1;
            SumDay = SumDay < 0 ? 0 : SumDay;
            cout << SumDay << " ";
        }
        else if (startMon < endMon)
        {
            SumDay += (MonthDay[startMon] - ((leftMax[3] - 48) * 10 + leftMax[4] - 48)) + 1;
            cout << SumDay << " ";
            SumDay += (rightMin[3] - 48) * 10 + rightMin[4] - 48;
            cout << SumDay << " ";
        }

        return SumDay;
    }
};